//
//  BookManager.m
//  03-HomeWork
//
//  Created by dllo on 16/7/6.
//  Copyright © 2016年 daming. All rights reserved.
//

#import "BookManager.h"
@implementation BookManager
/** 便利构造器 */
+ (instancetype)bookManagerWithBookArray {
    return [[BookManager alloc]init];
}
/** 添加一个书籍 */
- (void)addBookOfBookName:(NSString *)bookName
                bookPrice:(double)bookPrice {
    
    NSMutableArray *muArray = [NSMutableArray array];
    for (Book *book in self.bookArray) {
        [muArray addObject:book.bookName];
    }
    if ([muArray containsObject:bookName]) {
        NSLog(@"已有该书,无需添加!");
    } else {
        Book *book = [Book bookName:bookName bookPrice:bookPrice];
        [self.bookArray addObject:book];
        NSLog(@"添加书籍成功!");
    }
}
/** 删除一个书籍 */
- (void)deleteBookOfBookName:(NSString *)bookName {
    
    NSMutableArray *muArray = [NSMutableArray array];
    for (Book *book in self.bookArray) {
        [muArray addObject:book.bookName];
    }
    if ([muArray containsObject:bookName]) {
        NSInteger index = [muArray indexOfObject:bookName];
        [self.bookArray removeObjectAtIndex:index];
        NSLog(@"删除书籍成功!");
    } else {
        NSLog(@"没有这本书籍,无需删除!");
    }
}
/** 查找书籍并修改价格 */
- (void)searchAndchangeOfBookName:(NSString *)bookName
                        bookPrice:(double)bookPrice {
    
    NSMutableArray *muArray = [NSMutableArray array];
    for (Book *book in self.bookArray) {
        [muArray addObject:book.bookName];
    }
    if ([muArray containsObject:bookName]) {
        NSInteger index = [muArray indexOfObject:bookName];
        Book *book = [self.bookArray objectAtIndex:index];
        book.bookPrice = bookPrice;
    } else {
        NSLog(@"没有这本书,无法修改价格!");
    }
}
/** 展示所有书名 */
- (void)showAllBookName {
    
    for (Book *book in self.bookArray) {
        NSLog(@"书名:%@, 书的价格:%0.2f", book.bookName, book.bookPrice);
    }
}

@end
